package com.zide.operate.service.impl;

import java.util.Arrays;
import java.util.List;
import com.zide.common.core.domain.PageResult;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ArrayUtil;
import com.zide.common.core.vo.CommonParamIdVO;
import com.zide.common.utils.DateUtils;
import com.zide.operate.domain.po.OperateSupport;
import com.zide.operate.domain.vo.result.OperateSupportResultVO;
import com.zide.operate.domain.vo.save.OperateSupportSaveVO;
import com.zide.operate.domain.vo.search.OperateSupportSearchVO;
import com.zide.operate.mapper.OperateSupportMapper;
import com.zide.operate.service.IOperateSupportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 打赏支持Service业务层处理
 * 
 * @author zide
 * @date 2024-05-07
 */
@Slf4j
@Service
public class OperateSupportServiceImpl implements IOperateSupportService {
    @Autowired
    private OperateSupportMapper operateSupportMapper;

    /**
     * 查询打赏支持列表
     */
    @Override
    public PageResult<OperateSupportResultVO> searchOperateSupportPageList(OperateSupportSearchVO searchVO) {
        PageResult<OperateSupport> dbPageResult = operateSupportMapper.selectPage(searchVO);
        List<OperateSupportResultVO> resultList = BeanUtil.copyToList(dbPageResult.getList(),OperateSupportResultVO.class);
        PageResult<OperateSupportResultVO> result = new PageResult<>();
        result.setTotal(dbPageResult.getTotal());
        result.setList(resultList);
        return result;
    }

    /**
     * 查询打赏支持详情
     */
    @Override
    public OperateSupportResultVO selectOperateSupportById(Long id) {
            OperateSupport dbInfo = operateSupportMapper.selectById(id);
            OperateSupportResultVO result = BeanUtil.copyProperties(dbInfo,OperateSupportResultVO.class);
        return result;
    }

    /**
     * 新增打赏支持
     */
    @Override
    public int saveOperateSupport(OperateSupportSaveVO saveVO) {
        OperateSupport insertBean = BeanUtil.copyProperties(saveVO,OperateSupport.class);
        return operateSupportMapper.insert(insertBean);
    }

    /**
     * 修改打赏支持
     */
    @Override
    public int updateOperateSupport(OperateSupportSaveVO saveVO) {
        OperateSupport updateBean = BeanUtil.copyProperties(saveVO,OperateSupport.class);
        return operateSupportMapper.updateById(updateBean);
    }

    /**
     * 批量删除打赏支持
     */
    @Override
    public int removeOperateSupportByIds(CommonParamIdVO idVO) {
        if(ArrayUtil.isNotEmpty(idVO.getIds())) {
            return operateSupportMapper.deleteBatchIds(Arrays.asList(idVO.getIds()));
        }else {
            return operateSupportMapper.deleteById(idVO.getId());
        }

    }
}
